package stu.day33_day38.day36;

import java.util.Arrays;

public class hw3 {
    public int maxConsecutiveAnswers(String answerKey, int k) {

        int t_num = 0;
        int f_num = 0;

        int left = 0;
        int max = 0;
        for(int right=0;right<answerKey.length();right++){
            if(answerKey.charAt(right)=='T'){
                t_num++;
            }else {
                f_num++;
            }

            while (t_num>k&&f_num>k){
                if(answerKey.charAt(left)=='T'){
                    t_num--;
                }else {
                    f_num--;
                }
                left++;
            }
            max=Math.max(max,t_num+f_num);
        }
        return max;
    }


    public int minOperations(int[] nums, int x) {

        int left = 0;

        int sum = Arrays.stream(nums).sum();
        int target = sum-x;
        int min = Integer.MAX_VALUE;
        int num = 0;
        for(int right=0;right<nums.length;right++){
           num += nums[right];
            while(num>target&&left<=right){
                num -= nums[left];
                left++;
            }
            if(num==target){
                min = Math.min(min,nums.length-(right-left+1));
            }

        }
        return min==Integer.MAX_VALUE?-1:min;


    }






    public static void main(String[] args) {
        hw3 t = new hw3();
        t.maxConsecutiveAnswers("TTTTTFTFFT",2);
    }
}
